﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

public partial class PreliminaryApply : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //从请求中获得房源ID
            string HouseId = Context.Request.Params["HouseId"];
            //从请求中获得标识ID
            string RecordId = Context.Request.Params["RecordId"];

            if (!string.IsNullOrEmpty(HouseId))
            {
                //获取相应房源信息
                Chenxin.Lib.House.Entity.House_BaseInfo entHouseInfo = Chenxin.Lib.House.BLL.House_BaseInfo.GetHouseInfoEntity(HouseId);
                //转成Json，发回客户端
                hidHouseInfo.Value = Chenxin.Lib.Utility.JsonHelp.Convert2Json(entHouseInfo);

                //获取申请部门
                Chenxin.Lib.Business.Entity.t_Preliminary_BaseInfo entPreliminary = new Chenxin.Lib.Business.Entity.t_Preliminary_BaseInfo();
                entPreliminary.AppDepartId = CurrentUserInfo.DepartId;
                entPreliminary.AppDepartName = CurrentUserInfo.DepartName;
                entPreliminary.AppEmployeeId = CurrentUserInfo.UserId;
                entPreliminary.AppEmployeeName = CurrentUserInfo.UserName;
                hidAppDepart.Value = Chenxin.Lib.Utility.JsonHelp.Convert2Json(entPreliminary);

                //买方信息业务类
                Chenxin.Lib.Business.BLL.BuyerInfo bllBuyer = new Chenxin.Lib.Business.BLL.BuyerInfo();
                //出售方信息业务类
                Chenxin.Lib.Business.BLL.VenderInfo bllSaler = new Chenxin.Lib.Business.BLL.VenderInfo();

                //获取签约报备出售方信息
                List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2> lsSaler = bllSaler.LoadModel(new Guid(HouseId));
                //获取签约报备买方信息
                List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo1> lsBuyer = bllBuyer.LoadModel(new Guid(HouseId));

                hidLoadSaler.Value = Chenxin.Lib.Utility.JsonHelp.Convert2Json(lsSaler);
                hidLoadBuyer.Value = Chenxin.Lib.Utility.JsonHelp.Convert2Json(lsBuyer);
            }
            else if (!string.IsNullOrEmpty(RecordId))
            {
                //预审信息业务类
                Chenxin.Lib.Business.BLL.PreliminaryBaseInfo bllPreliminary = new Chenxin.Lib.Business.BLL.PreliminaryBaseInfo();
                //买方信息业务类
                Chenxin.Lib.Business.BLL.PreBuyerInfo bllPreBuyerInfo = new Chenxin.Lib.Business.BLL.PreBuyerInfo();
                //出售方信息业务类
                Chenxin.Lib.Business.BLL.PreSalerInfo bllPreSalerInfo = new Chenxin.Lib.Business.BLL.PreSalerInfo();

                //获取相应房源信息
                Chenxin.Lib.Business.Entity.t_Preliminary_BaseInfo entPreliminary = bllPreliminary.GetModel(new Guid(RecordId));
                //买方信息
                List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo1> lsPreBuyer = bllPreBuyerInfo.GetModelListByMainId(RecordId);
                ////出售方信息
                List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2> lsPreSaler = bllPreSalerInfo.GetModelListByMainId(RecordId);

                //转成Json，发回客户端
                hidPreliminaryInfo.Value = Chenxin.Lib.Utility.JsonHelp.Convert2Json(entPreliminary);
                //买方信息
                hidPreBuyerInfo.Value = Chenxin.Lib.Utility.JsonHelp.Convert2Json(lsPreBuyer);
                //出售方信息
                hidPreSalerInfo.Value = Chenxin.Lib.Utility.JsonHelp.Convert2Json(lsPreSaler);
            }
        }
        catch (Exception ex)
        {
            //Url参数出错，页面跳转
            Context.Response.Redirect(string.Format(ErrorPageUrl, ex.Message),false);
        }
    }
}
